// 返回路由里面的参数: 对象
function getQueryParams() {
	const result = {};
	const querystring = window.location.search;
	const reg = /[?&][^?&]+=[^?&]+/g;
	const found = querystring.match(reg);

	if (found) {
		found.forEach(item => {
			let temp = item.substring(1).split('=');
			let key = temp[0];
			let value = temp[1];
			result[key] = value;
		})
	}

	return result;
}

function myAjax(url) {
	const promise = new Promise((resolve, reject) => {
		const xhr = new XMLHttpRequest();
		xhr.open('GET', url, true);
		xhr.onreadystatechange = function() {
			console.log('xhr.readyState', xhr.readyState);
			if (xhr.readyState === 4) {
				if (xhr.status === 200) {
					resolve(JSON.parse(xhr.responseText));
				} else {
					reject(new Error('请求失败了'));
				}
			}
		};
		xhr.send(null);
	});

	return promise;
}

const url = '/mock/data1.json';
myAjax(url).then(data => {
	console.log('data', data);
}).catch(err => {
	console.error(err);
});

let wp=[{name:'wp',age:'12'},{name:'love',age:'36'},{name:'寸寸隽',age:'32'}];

wp.forEach(item => {
	item.love = 'love'
})